import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store'
import * as types from "../store/mutation-types";

Vue.use(Router)

const MyOrder = (resolve) => {
  import('components/my-order/my-order').then((module) => {
    resolve(module)
  })
}
const MyOrderCashback = (resolve) => {
  import('components/my-order/order-cashback').then((module) => {
    resolve(module)
  })
}
const MyOrderPromotion = (resolve) => {
  import('components/my-order/order-promotion').then((module) => {
    resolve(module)
  })
}
const MyOrderDetail = (resolve) => {
  import('components/my-order/my-order-detail').then((module) => {
    resolve(module)
  })
}
const OrderPromotionDetail = (resolve) => {
  import('components/my-order/order-promotion-detail').then((module) => {
    resolve(module)
  })
}
const MyCart = (resolve) => {
  import('components/my-cart/my-cart').then((module) => {
    resolve(module)
  })
}
const MyCartCashback = (resolve) => {
  import('components/my-cart/cart-cashback').then((module) => {
    resolve(module)
  })
}
const MyCartPromotion = (resolve) => {
  import('components/my-cart/cart-promotion').then((module) => {
    resolve(module)
  })
}
// const MyRqeuestDetail = (resolve) => {
//   import('components/my-request/my-request-detail').then((module) => {
//     resolve(module)
//   })
// }
const Home = (resolve) => {
  import('components/home/home').then((module) => {
    resolve(module)
  })
}
const Thank = (resolve) => {
  import('components/thank/thank').then((module) => {
    resolve(module)
  })
}
const Guide = (resolve) => {
  import('components/guide/guide').then((module) => {
    resolve(module)
  })
}
const newGuide = (resolve) => {
  import('components/new-guide/new-guide').then((module) => {
    resolve(module)
  })
}
const common = (resolve) => {
  import('components/common/common').then((module) => {
    resolve(module)
  })
}
const MyAccount = (resolve) => {
  import('components/my-account/my-account').then((module) => {
    resolve(module)
  })
}
const MyAccountDetail = (resolve) => {
  import('components/my-account/cashback-detail').then((module) => {
    resolve(module)
  })
}
const Categories = (resolve) => {
  import('components/categories/categories').then((module) => {
    resolve(module)
  })
}
const limitedDeals = (resolve) => {
  import('components/limited-deals/limited-deals').then((module) => {
    resolve(module)
  })
}
const Affiliate = (resolve) => {
  import('components/Affiliate/Affiliate').then((module) => {
    resolve(module)
  })
}
const Hot = (resolve) => {
  import('components/hot/hot').then((module) => {
    resolve(module)
  })
}
const New = (resolve) => {
  import('components/new/new').then((module) => {
    resolve(module)
  })
}
const Search = (resolve) => {
  import('components/search/search').then((module) => {
    resolve(module)
  })
}
const ProductDetail = (resolve) => {
  import('components/product-detail/product-detail').then((module) => {
    resolve(module)
  })
}
const SignIn = (resolve) => {
  import('base/sign-in/sign-in').then((module) => {
    resolve(module)
  })
}
const ForgotPassword = (resolve) => {
  import('components/forgot-password/forgot-password').then((module) => {
    resolve(module)
  })
}
const ForgotPasswordNext = (resolve) => {
  import('components/forgot-password/forgot-password-next').then((module) => {
    resolve(module)
  })
}
const promotionItem = (resolve) => {
  import('components/Promotion-Item/Promotion-Item').then((module) => {
    resolve(module)
  })
}
const payResult = (resolve) => {
  import('components/payResult/payResult').then((module) => {
    resolve(module)
  })
}
const aboutUs = (resolve) => {
  import('components/aboutUs/aboutUs').then((module) => {
    resolve(module)
  })
}
const termsAndConditions = (resolve) => {
  import('components/aboutUs/Terms and Conditions').then((module) => {
    resolve(module)
  })
}
const privacyStatement = (resolve) => {
  import('components/aboutUs/Privacy Statement').then((module) => {
    resolve(module)
  })
}
const EmailConfirm = (resolve) => {
  import('base/sign-in/email-confirm').then((module) => {
    resolve(module)
  })
}
const Activation = (resolve) => {
  import('base/sign-in/email-activation').then((module) => {
    resolve(module)
  })
}
const RefundPolicy = (resolve) => {
  import('components/refundPolicy/refundPolicy').then((module) => {
    resolve(module)
  })
}
const MyWishList = (resolve) => {
  import('components/my-wishlist/my-wishlist').then((module) => {
    resolve(module)
  })
}
const allCategories = (resolve) => {
  import('components/all-categories/all-categories').then((module) => {
    resolve(module)
  })
}
const Activity = (resolve) => {
  import('components/activity/activity').then(module => {
    resolve(module)
  })
}

const OrderGuide = (resolve) => {
  import('components/aboutUs/orderGuide').then(module => {
    resolve(module)
  })
}

const FAQ = (resolve) => {
  import('components/aboutUs/faq').then(module => {
    resolve(module)
  })
}

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    // 为活动页面留
    // {
    //   path: '/activity',
    //   component: Activity,
    //   meta: {
    //     isActivity: true
    //   }
    // },
    {
      path: '/activity/:name/:id',
      component: ProductDetail
    },
    {
      path: '/activity/:id',
      component: ProductDetail
    },
    {
      path: '/my-order',
      component: MyOrder,
      children: [
        {
          path:'cashback',
          component: MyOrderCashback
        },
        {
          path:'promotion',
          component: MyOrderPromotion
        },
        // 当进入到my-order时，下面的组件显示
        {
          path: "",
          component: MyOrderCashback
        }
      ],
      meta: {
        requireAuth: true
      }
    },
    {
      path: '/my-order/cashback/:name/:id',
      component: MyOrderDetail,
      meta: {
        requireAuth: true
      }
    },
    {
      path: '/my-order/cashback/:id',
      component: MyOrderDetail,
      meta: {
        requireAuth: true
      }
    },
    {
      path: '/my-order/promotion/:id',
      component: OrderPromotionDetail,
      meta: {
        requireAuth: true
      }
    },
    {
      path: '/my-cart',
      component: MyCart,
      children: [
        {
          path:'cashback',
          component: MyCartCashback
        },
        {
          path:'promotion',
          component: MyCartPromotion
        },
        // 当进入到my-order时，下面的组件显示
        {
          path: "",
          component: MyCartCashback
        }
      ],
      meta: {
        // requireAuth: true
      }
    },
    // {
    //   path: '/my-request/:id',
    //   component: MyRqeuestDetail,
    //   meta: {
    //     requireAuth: true
    //   }
    // },
    {
      path: '/thank',
      component: Thank
    },
    // 购物指南
    {
      path: '/order-guide',
      component: OrderGuide
    },
    // FAQ
    {
      path: '/FAQ',
      component: FAQ
    },
    {
      path: '/guide/:name/:id',
      component: Guide
    },
    {
      path: '/guide/:id',
      component: Guide
    },
    {
      path: '/new-guide/:name/:id',
      component: newGuide
    },
    {
      path: '/new-guide/:id',
      component: newGuide
    },
    {
      path: '/home',
      component: Home
    },
    {
      path: '/categories' ||'/categories/:name',
      component: Categories,
      children: [
        {
          path: ':id',
          component: common
        }
      ],
    },
    {
      path: '/categories/:name/:id'||'/categories/:name/:id/:three',
      component: Categories,
      children: [
        {
          path: ':id',
          component: common
        }
      ],
    },
    {
      path: '/category',
      component: Categories,
      children: [
        {
          path: ':id',
          component: common
        }
      ],
    },
    {
      path: '/all-categories',
      component: allCategories,
    },
    {
      path: '/limited-deals',
      component: limitedDeals,
    },
    {
      path: '/Affiliate',
      component: Affiliate,
    },
    {
      path: '/hot',
      component: Hot,
    },
    {
      path: '/new',
      component: New,
    },
    {
      path: '/search',
      component: Search,
    },
    {
      path: '/my-account',
      component: MyAccount
    },
    {
      path: '/my-account/cashback-detail',
      component: MyAccountDetail
    },
    {
      path: '/product-detail/:id',
      component: ProductDetail
    },
    {
      path: '/limited-deals/:name/:id',
      component: ProductDetail
    },
    {
      path: '/limited-deals/:id',
      component: ProductDetail
    },
    {
      path: '/Affiliate/:name/:id',
      component: ProductDetail
    },
    {
      path: '/Affiliate/:id',
      component: ProductDetail
    },
    {
      path: '/hot/:name/:id',
      component: ProductDetail
    },
    {
      path: '/hot/:id',
      component: ProductDetail
    },
    {
      path: '/new/:name/:id',
      component: ProductDetail
    },
    {
      path: '/new/:id',
      component: ProductDetail
    },
    {
      path: '/search/:name/:id',
      component: ProductDetail,
    },
    {
      path: '/search/:id',
      component: ProductDetail,
    },
    {
      path: '/category/:name/:id',
      component: ProductDetail
    },
    {
      path: '/category/:id',
      component: ProductDetail
    },
    {
      path: '/home/:name/:id',
      component: ProductDetail
    },
    {
      path: '/home/:id',
      component: ProductDetail
    },
    {
      path: '/sign-in',
      component: SignIn,
      name: 'SingIn',
      children: [
        // {
        //   path: 'redirect',
        //   component: Redirect
        // },
        // {
        //   path: 'email-confirm',
        //   component: EmailConfirm,
        // },
        // {
        //   path: 'email-activation',
        //   component: Activation,
        // },
      ]
    },
    {
      path: '/sign-in/email-confirm',
      component: EmailConfirm
    },
    {
      path: '/sign-in/email-activation',
      component: Activation
    },
    {
      path: '/forgot-password-next',
      component: ForgotPasswordNext,
    },
    {
      path: '/forgot-password',
      component: ForgotPassword,
    },
    {
      path: '/promotionItem',   //订单支付页面
      component: promotionItem,
      name:"promotionItem"
    },
    {
      path: '/payResult/:id',   //订单支付页面
      component: payResult,  //支付结果页
      name: 'payResult',  //支付结果页
    },
    {
      path: '/aboutUs',   //关于我们
      component: aboutUs,
    },
    {
      path: '/termsAndConditions',
      component: termsAndConditions,
    },
    {
      path: '/privacyStatement',
      component: privacyStatement,
    },
    {
      path: '/refundPolicy',
      component: RefundPolicy,
    },
    {
      path: '/my-wishlist',
        component: MyWishList,
    }
    ],
    //切换到新路由时，页面滚到顶部
    scrollBehavior (to, from, savedPosition) {
      if (savedPosition) {
        return savedPosition
      } else {
        return { x: 0, y: 0 }
      }
    }
})
//  判断是否需要登录权限 以及是否登录
// router.beforeEach((to, from, next) => {
//   if (to.matched.some(res => res.meta.requireAuth)) {// 判断是否需要登录权限
//     if (store.getters.token) {// 判断是否登录
//       next()
//     } else {// 没登录则跳转到登录界面
//       next({
//         path: '/sign-in',
//         query: {redirect: to.fullPath}
//       })
//     }
//   } else {
//     next()
//   }
//
//     if (to.matched.some(res => res.meta.isActivity)) {
//       store.commit(types.SET_IS_ACTIVITY, true)
//     } else {
//       store.commit(types.SET_IS_ACTIVITY, false)
//     }
//
// })

export default router
